package com.sakana.test1;

public class test2 {
    public static void main(String[] args) {
        System.out.println(toBinarySting(6));
        System.out.println(Integer.toBinaryString(6));
    }

    private static String toBinarySting(int number) {
        StringBuilder sb=new StringBuilder();
        //利用循环不断除2取余
        while (true){
            if(number==0){
                break;
            }

            int num=number%2;
            sb.insert(0,num);
            number=number/2;
        }
        return sb.toString();

    }
}
